﻿using System;
using System.Windows;

namespace c2iGMailNotifier
{
    public class ViewDefinition
    {
        public ViewDefinition(string regionKey, Type viewType)
        {
            if (viewType == null)
                throw new ArgumentNullException("viewType", "Le type ne peut être null");

            if (!viewType.IsSubclassOf(typeof(UIElement)))
                throw new ArgumentException("Le type doit être un UIElement", "viewType");

            this._controlType = viewType;
            this._regionKey = regionKey;
        }

        private UIElement _instance;
        private Type _controlType;
        private string _regionKey;

        public Type ControlType
        {
            get { return _controlType; }
        }

        public string RegionKey
        {
            get { return _regionKey; }
        }

        public UIElement GetInstance()
        {
            if (_instance == null)
                _instance = Activator.CreateInstance(this.ControlType) as UIElement;
            return _instance;
        }
    }
}